package views

import (
	"io/ioutil"
	"encoding/json"
	"text/template"
)

type Config struct {
	Name	string
	Intro	string
	Copyright	string
	Theme	string
	Mobile	string
	Duoshuo	string
}

func init(){
	bts, _ := ioutil.ReadFile("config.json")
	_ = json.Unmarshal(bts, cfg);

	// 常规访问模板
	themePath := "themes/" + cfg.Theme
	tmpls["view"] = template.Must(template.ParseFiles(
		themePath + "/base.tpl",
		themePath + "/header.tpl",
		themePath + "/footer.tpl",
		themePath + "/post.tpl",
		themePath + "/reserve.tpl",
		themePath + "/404.tpl",
		themePath + "/500.tpl",
	))
	// 手机访问模板
	themePath = "themes/" + cfg.Mobile
	tmpls["mobile"] = template.Must(template.ParseFiles(
		themePath + "/base.tpl",
		themePath + "/header.tpl",
		themePath + "/footer.tpl",
		themePath + "/post.tpl",
		themePath + "/reserve.tpl",
		themePath + "/404.tpl",
		themePath + "/500.tpl",
	))
	// 管理界面模板
	tmpls["admin"] = template.Must(template.ParseFiles(
		// 管理界面模版
		"admin/base.tpl",
		"admin/header.tpl",
		"admin/footer.tpl",
		"admin/editor.tpl",
		"admin/posts.tpl",
		"admin/help.tpl",
	))
}

var (
	// 皮肤模板
	tmpls = make(map[string]*template.Template)
	cfg = new(Config)
)
